/*
 * Copyright 2008 Zoundry LLC, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.zoundry.gaedt.ui.builders;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.core.resources.IResource;
import org.zoundry.gaedt.ui.builders.providers.ZGaeCSpecBuildProvider;


/**
 * Creates build providers for resources that need to be built.
 */
public class ZGaeBuildProviderFactory
{
    /** The singleton factory instance. */
    private static final ZGaeBuildProviderFactory sFactory = new ZGaeBuildProviderFactory();

    /**
     * Singleton instance.
     */
    public static final ZGaeBuildProviderFactory getInstance()
    {
        return sFactory;
    }
    
    /** A cache of all build providers. */
    private List<IZGaeBuildProvider> mAllProviders = new ArrayList<IZGaeBuildProvider>();

    /**
     * C'tor.
     */
    public ZGaeBuildProviderFactory()
    {
        initProviders();
    }

    /**
     * Initialize the list of providers.
     */
    private void initProviders()
    {
        getAllProviders().add(new ZGaeCSpecBuildProvider());
    }

    /**
     * Creates a list of providers for the given resource.
     *
     * @param aResource
     */
    public List<IZGaeBuildProvider> createProviders(IResource aResource)
    {
        List<IZGaeBuildProvider> providers = new LinkedList<IZGaeBuildProvider>();
        for (IZGaeBuildProvider provider : getAllProviders())
        {
            if (provider.accept(aResource))
                providers.add(provider);
        }
        return providers;
    }

    /**
     * @return the allProviders
     */
    protected List<IZGaeBuildProvider> getAllProviders()
    {
        return mAllProviders;
    }

    /**
     * @param aAllProviders the allProviders to set
     */
    protected void setAllProviders(List<IZGaeBuildProvider> aAllProviders)
    {
        mAllProviders = aAllProviders;
    }
}
